<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('用户列表')"/>
    <th:block th:include="include :: layout-latest-css"/>
    <th:block th:include="include :: ztree-css"/>
</head>
<body class="gray-bg">

<div class="ui-layout-center">
    <div class="layui-form-item">
        <div class="layui-input-block">
            <span style="margin-left: 5%">
            <input id="new" type="radio" name="sex" value="1" checked lay-filter="ChoiceRadio"
                   onclick="readyExecution()">
            <label class="layui-form-label">入库开单</label>
            </span>
            <span style="margin-left: 5%">
            <input id="auditing" type="radio" name="sex" value="2" lay-filter="ChoiceRadio"
                   onclick="auditingExecution()">
            <label class="layui-form-label">已审核</label>
            </span>
            <span style="margin-left: 5%">
            <input id="bein" type="radio" name="sex" value="3" lay-filter="ChoiceRadio" onclick="beinExecution()">
            <label class="layui-form-label">单据执行</label>
            </span>
            <span style="margin-left: 5%">
            <input id="execute" type="radio" name="sex" value="4" lay-filter="ChoiceRadio" onclick="executeExecution()">
            <label class="layui-form-label">执行完成</label>
            </span>
            <span style="margin-left: 5%">
            <input id="finish" type="radio" name="sex" value="5" lay-filter="ChoiceRadio" onclick="finishExecution()">
            <label class="layui-form-label">单据确认</label>
            </span>
            <span style="margin-left: 5%">
            <input id="cancel" type="radio" name="sex" value="6" lay-filter="ChoiceRadio" onclick="cancelExecution()">
            <label class="layui-form-label">单据作废</label>
            </span>
            <span style="margin-left: 5%">
            <input id="PostBack" type="radio" name="sex" value="7" lay-filter="ChoiceRadio"
                   onclick="postbackExecution()">
            <label class="layui-form-label">单据作废</label>
            </span>
        </div>
    </div>
    <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="user-form">
                    <input type="hidden" id="deptId" name="deptId">
                    <input type="hidden" id="parentId" name="parentId">
                    <div class="select-list">
                        <ul>
                            <li>
                                单据编号：<input type="text" name="in_type"/>
                            </li>
                            <li>
                                单据类型：<select name="status" th:with="type=${@dict.getType('sys_employee_status')}">
                                <option value="">采购入库</option>
                                <option value="">寄存入库</option>
                                <option value="">货物返回入库</option>
                                <option value="">自制入库</option>
                                <option value="">其他入库</option>
                                <!--                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>-->
                            </select>
                            </li>
                            <li>
                                建单人：<input type="text" name="create_man_id"/>
                            </li>
                            <li class="select-time">
                                <label>建单时间： </label>
                                <input type="text" class="time-input" id="startTime" placeholder="开始时间"
                                       name="create_date"/>
                                <span>-</span>
                                <input type="text" class="time-input" id="endTime" placeholder="结束时间"
                                       name="create_date"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                        class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                        class="fa fa-refresh"></i>&nbsp;重置</a>

                                <a class="btn btn-primary btn-rounded btn-sm" onclick="sureque()"><i
                                        class="fa fa-search"></i>&nbsp;单据审核</a>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="sureIn()"><i
                                        class="fa fa-search"></i>&nbsp;单据确认</a>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="cancelIn()"><i
                                        class="fa fa-search"></i>&nbsp;单据作废</a>

                            </li>
                        </ul>
                    </div>
                </form>


            </div>



            <div class="col-sm-12 select-table table-striped">
<!--                <div class="btn-group-sm" id="toolbar" role="group">-->
                <span style="float: left">
                    <a class="btn btn-success" onclick="$.operate.addTab()" shiro:hasPermission="system:user:add">
                        <i class="fa fa-plus"></i> 新增
                    </a>
                </span>
<!--                </div>-->
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
</div>

<th:block th:include="include :: footer"/>
<th:block th:include="include :: layout-latest-js"/>
<th:block th:include="include :: ztree-js"/>
<script th:inline="javascript">
    var editFlags = [[${@permission.hasPermi('system:item')}]];
    var editFlag = [[${@permission.hasPermi('system:item:edit')}]];
    var removeFlag = [[${@permission.hasPermi('system:user:remove')}]];
    var editsFlag = [[${@permission.hasPermi('system:item:edits')}]];
    var resetPwdFlag = [[${@permission.hasPermi('system:user:resetPwd')}]];
    var prefix = ctx + "system/item";

    //入库开单
    function readyExecution() {
        initTable();
        yc();
        $("#bootstrap-table").bootstrapTable('load', {
            "status": $("#new").val()
        });
    }

    //已审核
    function auditingExecution() {
        initTable();
        yc();
        $("#bootstrap-table").bootstrapTable('load', {
            "status": $("#auditing").val()
        });
    }

    //单据执行
    function beinExecution() {
        initTable();
        yc();
        $("#bootstrap-table").bootstrapTable('load', {
            "status": $("#bein").val()
        });
    }

    //执行完成
    function executeExecution() {
        initTable();
        yc();
        $("#bootstrap-table").bootstrapTable('load', {
            "status": $("#execute").val()
        });
    }

    //单据确认
    function finishExecution() {
        initTable();
        yc();
        $("#bootstrap-table").bootstrapTable('load', {
            "status": $("#finish").val()
        });
    }

    //单据作废
    function cancelExecution() {
        initTable();
        yc();
        $("#bootstrap-table").bootstrapTable('load', {
            "status": $("#cancel").val()
        });
    }

    //回传完成
    function postbackExecution() {
        initTable();
        yc();
        $("#bootstrap-table").bootstrapTable('load', {
            "status": $("#PostBack").val()
        });
    }

    function yc() {
        var aimName = "bill";
        $.ajax({
            "url": "/sys/setting/seachyc?tablename=" + aimName,
            "type": "GET",
            "dataType": "json",
            "success": function (result) {
                if (result.success == 1) {

                    var ccc = result.errorInfo;
                    var str = ccc.split(",");

                    // $.messager.alert("系统提示", "刷新成功！");
                    for (var i = 0; i < str.length; i++) {
                        $('#bootstrap-table').val(result);
                    }

                    //$('#dg').datagrid('hideColumn','remark');
                    //$.messager.alert("系统提示","提交失败，请联系管理员嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻！");
                } else {
                    $.messager.alert("系统提示", "提交失败，请联系管理员！");
                }
            }
        });
    }
    //单据审核
    function sureIn() {
        var selectedRows = $("#bootstrap-table").bootstrapTable("getSelections");
        if (selectedRows.length != 1) {
            $.messager.alert("系统提示", "请选择一条要操作的数据！");
            return;
        }
        var status=selectedRows[0].status;
        if (status == "1") {
            $.messager.alert("系统提示", "未执行单据无法确认！");
            return;
        }
        var stockin_guid = selectedRows[0].stockin_guid;
        $.post("/in/stockin/update", {
            stockin_guid : stockin_guid,
            status : "5"
        }, function(result) {
            if (result.success == '1') {
                $.messager.alert("系统提示", "确认成功！");
                $("#bootstrap-table").bootstrapTable("load");
            } else {
                $.messager.alert("系统提示",result.errorInfo);
            }
        }, "json");

    }
    //单据确认
    function sureque() {
        var selectedRows = $("#bootstrap-table").bootstrapTable("getSelections");
        if (selectedRows.length != 1) {
            $.messager.alert("系统提示", "请选择一条要操作的数据！");
            return;
        }
        var status=selectedRows[0].status;
        if (status != "1") {
            $.messager.alert("系统提示", "只能审核未执行的单据！");
            return;
        }
        var stockin_guid = selectedRows[0].stockin_guid;
        $.post("/in/stockin/update1", {
            stockin_guid : stockin_guid,

        }, function(result) {
            if (result.success == '1') {
                $.messager.alert("系统提示", "审核成功！");
                $("#bootstrap-table").bootstrapTable("load");
            } else {
                $.messager.alert("系统提示",result.errorInfo);
            }
        }, "json");

    }
    //单据作废
    function cancelIn() {
        var selectedRows = $("#bootstrap-table").bootstrapTable("getSelections");
        var opts = $("#bootstrap-table").bootstrapTable("options");
        if (selectedRows.length != 1) {
            $.messager.alert("系统提示", "请选择一条要操作的数据！");
            return;
        }
        var status=selectedRows[0].status;
        if (status == "2") {
            $.messager.alert("系统提示", "正执行单据无法作废！");
            return;
        }
        var stockin_guid = selectedRows[0].stockin_guid;
        $.post("/in/stockin/update", {
            stockin_guid : stockin_guid,
            status : "6"
        }, function(result) {
            if (result.success == '1') {
                $.messager.alert("系统提示", "作废成功！");
                $("#bootstrap-table").bootstrapTable("load");
            } else {
                $.messager.alert("系统提示",result.errorInfo);
            }
        }, "json");

    }

    //页面加载完成后执行
    $(function () {
        var panehHidden = false;
        if ($(this).width() < 769) {
            panehHidden = true;
        }
        $('body').layout({initClosed: panehHidden, west__size: 185});
        // 回到顶部绑定
        if ($.fn.toTop !== undefined) {
            var opt = {
                win: $('.ui-layout-center'),
                doc: $('.ui-layout-center')
            };
            $('#scroll-up').toTop(opt);
        }
        initTable();
    });

    // window.onload=initTable;
    function initTable() {
        $("#bootstrap-table").bootstrapTable({
            // url: '/db/log/list.do',
            url: prefix + "/list",
            detailView: true,//父子表
            search: false,
            showRefresh: true,
            showColumns: true,
            minimumCountColumns: 2,
            clickToSelect: true,//是否启用点击选中行
            uniqueId: "stockin_guid",//每一行的唯一标识，一般为主键列
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            importUrl: prefix + "/importData",
            importTemplateUrl: prefix + "/importTemplate",
            sortName: "createTime",
            sortOrder: "desc",
            modalName: "项目",
            method: 'get',
            // queryParams: {id: parentid},
            // ajaxOptions: {id: parentid},
            striped: true, //是否显示行间隔色
            pagination: true,//显示分页
            sidePagination: "client",
            pageNumber: 1,
            pageSize: 15,
            pageList: [10, 25],
            columns:
                [{
                    checkbox: true,

                },
                    {
                        field: 'stockin_guid',
                        title: 'ID',
                        visible: false
                    },
                    {
                        field: 'stockin_id',
                        title: '入库订单主表id',
                        visible: false
                    },
                    {
                        field: 'in_type',
                        title: '订单类型',
                        sortable: true
                    },


                    {
                        field: 'create_date',
                        title: '建单时间',
                        visible: true
                    },

                    {
                        field: 'supplier_id',
                        title: '供应商id'
                    },


                    {
                        field: 'customer_id',
                        title: '客户id',
                        align: 'center',

                    },
                    {
                        field: 'create_man_id',
                        title: '建单人id',
                        sortable: true,
                    },
                    {
                        field: 'status',
                        title: '订单状态',
                        visible: true

                    },
                    {
                        field: 'warehouse_id',
                        title: '库房id',
                        visible: true

                    },
                    {
                        field: 'stockin_source',
                        title: '###',
                        visible: true

                    },
                    {
                        field: 'class_now_id',
                        title: '操作当前班组id',
                        visible: true

                    },
                    {
                        field: 'line_id',
                        title: '生产线编号',
                        visible: true

                    },
                    {
                        field: 'finish_date',
                        title: '结束日期',
                        visible: true

                    },

                    {
                        title: '操作',
                        align: 'center',
                        formatter: function (value, row, index) {
                            var actions = [];
                            /*actions.push("<a class='btn  btn-success btn-xs " + editFlag + "' href='javascript:void(0)' onclick='detail(" + row.prjgroupId + ")'><i class='fa fa-details'></i>项目详情</a>");*/
                            actions.push('<a class="btn btn-primary btn-xs ' + editsFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.prjID + '\')"><i class="fa fa-edit"></i>修改</a> ');
                            actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.prjID + '\')"><i class="fa fa-remove"></i>删除</a> ');
                            var more = [];
                            more.push("<a class='btn btn-default btn-xs " + resetPwdFlag + "' href='javascript:void(0)' onclick='resetPwd(" + row.userId + ")'><i class='fa fa-key'></i>重置密码</a> ");
                            more.push("<a class='btn btn-default btn-xs " + editFlag + "' href='javascript:void(0)' onclick='authRole(" + row.userId + ")'><i class='fa fa-check-square-o'></i>分配角色</a>");
                            return actions.join('');
                        }
                    },],
            //注册加载子表的事件。注意下这里的三个参数！
            onExpandRow: function (index, row, $detail) {
                initSubTable(index, row, $detail);
            }
        });
        //初始化子表格(无线循环)
        initSubTable = function (index, row, $detail) {
            var parentid = row.id;
            var cur_table = $detail.html('<table></table>').find('table');
            $(cur_table).bootstrapTable({
                url: prefix + "/list",
                detailView: true,//父子表
                search: false,
                showRefresh: true,
                showColumns: true,
                minimumCountColumns: 2,
                clickToSelect: true,//是否启用点击选中行
                uniqueId: "stockin_guid",//每一行的唯一标识，一般为主键列
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                importUrl: prefix + "/importData",
                importTemplateUrl: prefix + "/importTemplate",
                sortName: "createTime",
                sortOrder: "desc",
                modalName: "项目",
                method: 'get',
                queryParams: {id: parentid},
                ajaxOptions: {id: parentid},
                striped: true, //是否显示行间隔色
                pagination: true,//显示分页
                sidePagination: "client",
                pageNumber: 1,
                pageSize: 15,
                pageList: [10, 25],
                columns:
                    [{
                        checkbox: true,

                    },
                        {
                            field: 'stockin_guid',
                            title: 'ID',
                            visible: false
                        },
                        {
                            field: 'stockin_id',
                            title: '入库订单主表id',
                            visible: false
                        },
                        {
                            field: 'in_type',
                            title: '订单类型',
                            sortable: true
                        },


                        {
                            field: 'create_date',
                            title: '建单时间',
                            visible: true
                        },

                        {
                            field: 'supplier_id',
                            title: '供应商id'
                        },


                        {
                            field: 'customer_id',
                            title: '客户id',
                            align: 'center',

                        },
                        {
                            field: 'create_man_id',
                            title: '建单人id',
                            sortable: true,
                        },
                        {
                            field: 'status',
                            title: '订单状态',
                            visible: true

                        },
                        {
                            field: 'warehouse_id',
                            title: '库房id',
                            visible: true

                        },
                        {
                            field: 'stockin_source',
                            title: '###',
                            visible: true

                        },
                        {
                            field: 'class_now_id',
                            title: '操作当前班组id',
                            visible: true

                        },
                        {
                            field: 'line_id',
                            title: '生产线编号',
                            visible: true

                        },
                        {
                            field: 'finish_date',
                            title: '结束日期',
                            visible: true

                        },

                        {
                            title: '操作',
                            align: 'center',
                            formatter: function (value, row, index) {
                                var actions = [];
                                /*actions.push("<a class='btn  btn-success btn-xs " + editFlag + "' href='javascript:void(0)' onclick='detail(" + row.prjgroupId + ")'><i class='fa fa-details'></i>项目详情</a>");*/
                                actions.push('<a class="btn btn-primary btn-xs ' + editsFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.prjID + '\')"><i class="fa fa-edit"></i>修改</a> ');
                                actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.prjID + '\')"><i class="fa fa-remove"></i>删除</a> ');
                                var more = [];
                                more.push("<a class='btn btn-default btn-xs " + resetPwdFlag + "' href='javascript:void(0)' onclick='resetPwd(" + row.userId + ")'><i class='fa fa-key'></i>重置密码</a> ");
                                more.push("<a class='btn btn-default btn-xs " + editFlag + "' href='javascript:void(0)' onclick='authRole(" + row.userId + ")'><i class='fa fa-check-square-o'></i>分配角色</a>");
                                return actions.join('');
                            }
                        },],

                //无线循环取子表，直到子表里面没有记录
                onExpandRow: function (index, row, $Subdetail) {
                    initSubTable(index, row, $Subdetail);
                }
            });
        };
    }


    function detail(prjgroupId) {
        var url = prefix + '/detail/' + prjgroupId;
        $.modal.openTab("项目详情", url);
    }

    function queryDeptTree() {
        var url = ctx + "system/dept/treeData";
        var options = {
            url: url,
            expandLevel: 2,
            onClick: zOnClick
        };
        $.tree.init(options);

        function zOnClick(event, treeId, treeNode) {
            $("#deptId").val(treeNode.id);
            $("#parentId").val(treeNode.pId);
            $.table.search();
        }
    }

    $('#btnExpand').click(function () {
        $._tree.expandAll(true);
        $(this).hide();
        $('#btnCollapse').show();
    });

    $('#btnCollapse').click(function () {
        $._tree.expandAll(false);
        $(this).hide();
        $('#btnExpand').show();
    });

    $('#btnRefresh').click(function () {
        queryDeptTree();
    });

</script>
</body>
<!-- 导入区域 -->
<script id="importTpl" type="text/template">
    <form enctype="multipart/form-data" class="mt20 mb10">
        <div class="col-xs-offset-1">
            <input type="file" id="file" name="file"/>
            <div class="mt10 pt5">
                <input type="checkbox" id="updateSupport" name="updateSupport" title="如果登录账户已经存在，更新这条数据。"> 是否更新已经存在的用户数据
                &nbsp; <a onclick="$.table.importTemplate()" class="btn btn-default btn-xs"><i
                    class="fa fa-file-excel-o"></i> 下载模板</a>
            </div>
            <font color="red" class="pull-left mt10">
                提示：仅允许导入“xls”或“xlsx”格式文件！
            </font>
        </div>
    </form>
</script>
</html>